home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / Direct3D / DXTex / dialogs.cpp < prev    next >
C/C++ Source or Header  |  2001-10-08  |  12KB  |  455 lines

  1. // Dialogs.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "dxtex.h"
  6. #include "dialogs.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CNewTextureDlg dialog
  16.  
  17.  
  18. CNewTextureDlg::CNewTextureDlg(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CNewTextureDlg::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CNewTextureDlg)
  22.     m_iTexType = 0;
  23.     m_dwWidth = 256;
  24.     m_dwHeight = 256;
  25.     m_dwDepth = 8;
  26.     m_iFmt = 0;
  27.     m_strFmtDesc = _T("");
  28.     m_numMips = 1;
  29.     //}}AFX_DATA_INIT
  30. }
  31.  
  32.  
  33. void CNewTextureDlg::DoDataExchange(CDataExchange* pDX)
  34. {
  35.     CDialog::DoDataExchange(pDX);
  36.     //{{AFX_DATA_MAP(CNewTextureDlg)
  37.     DDX_Radio(pDX, IDC_TEXTURE, m_iTexType);
  38.     DDX_Text(pDX, IDC_WIDTH, m_dwWidth);
  39.     DDV_MinMaxInt(pDX, m_dwWidth, 1, 1024);
  40.     DDX_Text(pDX, IDC_HEIGHT, m_dwHeight);
  41.     DDV_MinMaxInt(pDX, m_dwHeight, 1, 1024);
  42.     DDX_Text(pDX, IDC_DEPTH, m_dwDepth);
  43.     DDV_MinMaxInt(pDX, m_dwDepth, 2, 1024);
  44.     DDX_Radio(pDX, IDC_A8R8G8B8, m_iFmt);
  45.     DDX_Text(pDX, IDC_FMTDESC, m_strFmtDesc);
  46.     DDX_Text(pDX, IDC_MIPCOUNT, m_numMips);
  47.     DDV_MinMaxInt(pDX, m_numMips, 1, 20);
  48.     //}}AFX_DATA_MAP
  49. }
  50.  
  51.  
  52. BEGIN_MESSAGE_MAP(CNewTextureDlg, CDialog)
  53.     //{{AFX_MSG_MAP(CNewTextureDlg)
  54.     ON_BN_CLICKED(IDC_TEXTURE, OnChangeTextureType)
  55.     ON_BN_CLICKED(IDC_A8R8G8B8, OnChangeFormat)
  56.     ON_BN_CLICKED(IDC_VOLUMETEXTURE, OnChangeTextureType)
  57.     ON_BN_CLICKED(IDC_CUBEMAP, OnChangeTextureType)
  58.     ON_BN_CLICKED(IDC_A4R4G4B4, OnChangeFormat)
  59.     ON_BN_CLICKED(IDC_A1R5G5B5, OnChangeFormat)
  60.     ON_BN_CLICKED(IDC_R5G6B5, OnChangeFormat)
  61.     ON_BN_CLICKED(IDC_R8G8B8, OnChangeFormat)
  62.     ON_BN_CLICKED(IDC_X8R8G8B8, OnChangeFormat)
  63.     ON_BN_CLICKED(IDC_X1R5G5B5, OnChangeFormat)
  64.     ON_BN_CLICKED(IDC_R3G3B2, OnChangeFormat)
  65.     ON_BN_CLICKED(IDC_A8R3G3B2, OnChangeFormat)
  66.     ON_BN_CLICKED(IDC_X4R4G4B4, OnChangeFormat)
  67.     ON_BN_CLICKED(IDC_DXT1, OnChangeFormat)
  68.     ON_BN_CLICKED(IDC_DXT2, OnChangeFormat)
  69.     ON_BN_CLICKED(IDC_DXT3, OnChangeFormat)
  70.     ON_BN_CLICKED(IDC_DXT4, OnChangeFormat)
  71.     ON_BN_CLICKED(IDC_DXT5, OnChangeFormat)
  72.     //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CNewTextureDlg message handlers
  77.  
  78. BOOL CNewTextureDlg::OnInitDialog() 
  79. {
  80.     CDialog::OnInitDialog();
  81.     
  82.     OnChangeTextureType();
  83.     OnChangeFormat();
  84.  
  85.     return TRUE;  // return TRUE unless you set the focus to a control
  86.                   // EXCEPTION: OCX Property Pages should return FALSE
  87. }
  88.  
  89.  
  90. void CNewTextureDlg::OnChangeTextureType() 
  91. {
  92.     UpdateData(TRUE);
  93.  
  94.     if (m_iTexType == 2)
  95.     {
  96.         // Volume Tex
  97.         GetDlgItem(IDC_VOLUMEDEPTHLABEL)->EnableWindow(TRUE);
  98.         GetDlgItem(IDC_DEPTH)->EnableWindow(TRUE);
  99.     }
  100.     else
  101.     {
  102.         // Normal or Cube Tex
  103.         GetDlgItem(IDC_VOLUMEDEPTHLABEL)->EnableWindow(FALSE);
  104.         GetDlgItem(IDC_DEPTH)->EnableWindow(FALSE);
  105.     }
  106.     UpdateData(FALSE);
  107.     OnChangeFormat();
  108. }
  109.  
  110.  
  111.  
  112. void CNewTextureDlg::OnChangeFormat() 
  113. {
  114.     UpdateData(TRUE);
  115.     switch (m_iFmt)
  116.     {
  117.     case 0:
  118.         m_fmt = D3DFMT_A8R8G8B8;
  119.         m_strFmtDesc.LoadString(IDS_FMTDESC_A8R8G8B8);
  120.         break;
  121.     case 1:
  122.         m_fmt = D3DFMT_A1R5G5B5;
  123.         m_strFmtDesc.LoadString(IDS_FMTDESC_A1R5G5B5);
  124.         break;
  125.     case 2:
  126.         m_fmt = D3DFMT_A4R4G4B4;
  127.         m_strFmtDesc.LoadString(IDS_FMTDESC_A4R4G4B4);
  128.         break;
  129.     case 3:
  130.         m_fmt = D3DFMT_R8G8B8;
  131.         m_strFmtDesc.LoadString(IDS_FMTDESC_R8G8B8);
  132.         break;
  133.     case 4:
  134.         m_fmt = D3DFMT_R5G6B5;
  135.         m_strFmtDesc.LoadString(IDS_FMTDESC_R5G6B5);
  136.         break;
  137.     case 5:
  138.         m_fmt = D3DFMT_X8R8G8B8;
  139.         m_strFmtDesc.LoadString(IDS_FMTDESC_X8R8G8B8);
  140.         break;
  141.     case 6:
  142.         m_fmt = D3DFMT_X1R5G5B5;
  143.         m_strFmtDesc.LoadString(IDS_FMTDESC_X1R5G5B5);
  144.         break;
  145.     case 7:
  146.         m_fmt = D3DFMT_R3G3B2;
  147.         m_strFmtDesc.LoadString(IDS_FMTDESC_R3G3B2);
  148.         break;
  149.     case 8:
  150.         m_fmt = D3DFMT_A8R3G3B2;
  151.         m_strFmtDesc.LoadString(IDS_FMTDESC_A8R3G3B2);
  152.         break;
  153.     case 9:
  154.         m_fmt = D3DFMT_X4R4G4B4;
  155.         m_strFmtDesc.LoadString(IDS_FMTDESC_X4R4G4B4);
  156.         break;
  157.     case 10:
  158.         m_fmt = D3DFMT_DXT1;
  159.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT1);
  160.         break;
  161.     case 11:
  162.         m_fmt = D3DFMT_DXT2;
  163.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT2);
  164.         break;
  165.     case 12:
  166.         m_fmt = D3DFMT_DXT3;
  167.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT3);
  168.         break;
  169.     case 13:
  170.         m_fmt = D3DFMT_DXT4;
  171.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT4);
  172.         break;
  173.     case 14:
  174.         m_fmt = D3DFMT_DXT5;
  175.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT5);
  176.         break;
  177.     }
  178.     UpdateData(FALSE);
  179. }
  180.  
  181. void CNewTextureDlg::OnOK() 
  182. {
  183.     UpdateData(TRUE);
  184.  
  185.     // TODO: Need to do lots of validation of width/height/depth/mipcount here
  186.  
  187.     if (m_iTexType != 2)
  188.         m_dwDepth = 0;
  189.  
  190.     switch (m_iFmt)
  191.     {
  192.     case 0:  m_fmt = D3DFMT_A8R8G8B8;   break;
  193.     case 1:  m_fmt = D3DFMT_A1R5G5B5;   break;
  194.     case 2:  m_fmt = D3DFMT_A4R4G4B4;   break;
  195.     case 3:  m_fmt = D3DFMT_R8G8B8;     break;
  196.     case 4:  m_fmt = D3DFMT_R5G6B5;     break;
  197.     case 5:  m_fmt = D3DFMT_X8R8G8B8;   break;
  198.     case 6:  m_fmt = D3DFMT_X1R5G5B5;   break;
  199.     case 7:  m_fmt = D3DFMT_R3G3B2;     break;
  200.     case 8:  m_fmt = D3DFMT_A8R3G3B2;   break;
  201.     case 9:  m_fmt = D3DFMT_X4R4G4B4;   break;
  202.     case 10: m_fmt = D3DFMT_DXT1;       break;
  203.     case 11: m_fmt = D3DFMT_DXT2;       break;
  204.     case 12: m_fmt = D3DFMT_DXT3;       break;
  205.     case 13: m_fmt = D3DFMT_DXT4;       break;
  206.     case 14: m_fmt = D3DFMT_DXT5;       break;
  207.     }
  208.  
  209.     CDialog::OnOK();
  210. }
  211.  
  212. /////////////////////////////////////////////////////////////////////////////
  213. // CCubeMapDlg dialog
  214.  
  215.  
  216. CCubeMapDlg::CCubeMapDlg(CWnd* pParent /*=NULL*/)
  217.     : CDialog(CCubeMapDlg::IDD, pParent)
  218. {
  219.     //{{AFX_DATA_INIT(CCubeMapDlg)
  220.     m_iFace = 0;
  221.     //}}AFX_DATA_INIT
  222. }
  223.  
  224.  
  225. void CCubeMapDlg::DoDataExchange(CDataExchange* pDX)
  226. {
  227.     CDialog::DoDataExchange(pDX);
  228.     //{{AFX_DATA_MAP(CCubeMapDlg)
  229.     DDX_Radio(pDX, IDC_POSX, m_iFace);
  230.     //}}AFX_DATA_MAP
  231. }
  232.  
  233.  
  234. BEGIN_MESSAGE_MAP(CCubeMapDlg, CDialog)
  235.     //{{AFX_MSG_MAP(CCubeMapDlg)
  236.         // NOTE: the ClassWizard will add message map macros here
  237.     //}}AFX_MSG_MAP
  238. END_MESSAGE_MAP()
  239.  
  240.  
  241. /////////////////////////////////////////////////////////////////////////////
  242. // CVolumeMapDlg dialog
  243.  
  244.  
  245. CVolumeMapDlg::CVolumeMapDlg(CWnd* pParent /*=NULL*/)
  246.     : CDialog(CVolumeMapDlg::IDD, pParent)
  247. {
  248.     //{{AFX_DATA_INIT(CVolumeMapDlg)
  249.     m_powLayers = 0;
  250.     //}}AFX_DATA_INIT
  251. }
  252.  
  253.  
  254. void CVolumeMapDlg::DoDataExchange(CDataExchange* pDX)
  255. {
  256.     CDialog::DoDataExchange(pDX);
  257.     //{{AFX_DATA_MAP(CVolumeMapDlg)
  258.     DDX_Radio(pDX, IDC_RADIO2, m_powLayers);
  259.     //}}AFX_DATA_MAP
  260. }
  261.  
  262.  
  263. BEGIN_MESSAGE_MAP(CVolumeMapDlg, CDialog)
  264.     //{{AFX_MSG_MAP(CVolumeMapDlg)
  265.         // NOTE: the ClassWizard will add message map macros here
  266.     //}}AFX_MSG_MAP
  267. END_MESSAGE_MAP()
  268.  
  269. /////////////////////////////////////////////////////////////////////////////
  270. // CVolumeMapDlg message handlers
  271.  
  272.  
  273. /////////////////////////////////////////////////////////////////////////////
  274. // CChangeFmtDlg dialog
  275.  
  276.  
  277. CChangeFmtDlg::CChangeFmtDlg(CWnd* pParent /*=NULL*/)
  278.     : CDialog(CChangeFmtDlg::IDD, pParent)
  279. {
  280.     //{{AFX_DATA_INIT(CChangeFmtDlg)
  281.     m_iFmt = -1;
  282.     m_strFmtDesc = _T("");
  283.     //}}AFX_DATA_INIT
  284. }
  285.  
  286.  
  287. void CChangeFmtDlg::DoDataExchange(CDataExchange* pDX)
  288. {
  289.     CDialog::DoDataExchange(pDX);
  290.     //{{AFX_DATA_MAP(CChangeFmtDlg)
  291.     DDX_Radio(pDX, IDC_A8R8G8B8, m_iFmt);
  292.     DDX_Text(pDX, IDC_FMTDESC, m_strFmtDesc);
  293.     //}}AFX_DATA_MAP
  294. }
  295.  
  296.  
  297. BEGIN_MESSAGE_MAP(CChangeFmtDlg, CDialog)
  298.     //{{AFX_MSG_MAP(CChangeFmtDlg)
  299.     ON_BN_CLICKED(IDC_A1R5G5B5, OnChangeFmt)
  300.     ON_BN_CLICKED(IDC_A4R4G4B4, OnChangeFmt)
  301.     ON_BN_CLICKED(IDC_A8R8G8B8, OnChangeFmt)
  302.     ON_BN_CLICKED(IDC_R5G6B5, OnChangeFmt)
  303.     ON_BN_CLICKED(IDC_R8G8B8, OnChangeFmt)
  304.     ON_BN_CLICKED(IDC_X8R8G8B8, OnChangeFmt)
  305.     ON_BN_CLICKED(IDC_X1R5G5B5, OnChangeFmt)
  306.     ON_BN_CLICKED(IDC_R3G3B2, OnChangeFmt)
  307.     ON_BN_CLICKED(IDC_A8R3G3B2, OnChangeFmt)
  308.     ON_BN_CLICKED(IDC_X4R4G4B4, OnChangeFmt)
  309.     ON_BN_CLICKED(IDC_DXT1, OnChangeFmt)
  310.     ON_BN_CLICKED(IDC_DXT2, OnChangeFmt)
  311.     ON_BN_CLICKED(IDC_DXT3, OnChangeFmt)
  312.     ON_BN_CLICKED(IDC_DXT4, OnChangeFmt)
  313.     ON_BN_CLICKED(IDC_DXT5, OnChangeFmt)
  314.     //}}AFX_MSG_MAP
  315. END_MESSAGE_MAP()
  316.  
  317. /////////////////////////////////////////////////////////////////////////////
  318. // CChangeFmtDlg message handlers
  319.  
  320. BOOL CChangeFmtDlg::OnInitDialog() 
  321. {
  322.     CDialog::OnInitDialog();
  323.     
  324.     switch (m_fmt)
  325.     {
  326.     case D3DFMT_A8R8G8B8:
  327.         m_iFmt = 0;
  328.         break;
  329.     case D3DFMT_A1R5G5B5:
  330.         m_iFmt = 1;
  331.         break;
  332.     case D3DFMT_A4R4G4B4:
  333.         m_iFmt = 2;
  334.         break;
  335.     case D3DFMT_R8G8B8:
  336.         m_iFmt = 3;
  337.         break;
  338.     case D3DFMT_R5G6B5:
  339.         m_iFmt = 4;
  340.         break;
  341.     case D3DFMT_X8R8G8B8:
  342.         m_iFmt = 5;
  343.         break;
  344.     case D3DFMT_X1R5G5B5:
  345.         m_iFmt = 6;
  346.         break;
  347.     case D3DFMT_R3G3B2:
  348.         m_iFmt = 7;
  349.         break;
  350.     case D3DFMT_A8R3G3B2:
  351.         m_iFmt = 8;
  352.         break;
  353.     case D3DFMT_X4R4G4B4:
  354.         m_iFmt = 9;
  355.         break;
  356.     case D3DFMT_DXT1:
  357.         m_iFmt = 10;
  358.         break;
  359.     case D3DFMT_DXT2:
  360.         m_iFmt = 11;
  361.         break;
  362.     case D3DFMT_DXT3:
  363.         m_iFmt = 12;
  364.         break;
  365.     case D3DFMT_DXT4:
  366.         m_iFmt = 13;
  367.         break;
  368.     case D3DFMT_DXT5:
  369.         m_iFmt = 14;
  370.         break;
  371.     }
  372.  
  373.     UpdateFmtDesc();    
  374.  
  375.     UpdateData(FALSE);
  376.  
  377.     return TRUE;  // return TRUE unless you set the focus to a control
  378.                   // EXCEPTION: OCX Property Pages should return FALSE
  379. }
  380.  
  381. void CChangeFmtDlg::OnChangeFmt() 
  382. {
  383.     UpdateData(TRUE);
  384.     UpdateFmtDesc();
  385. }
  386.  
  387. void CChangeFmtDlg::UpdateFmtDesc()
  388. {
  389.     switch (m_iFmt)
  390.     {
  391.     case 0:
  392.         m_fmt = D3DFMT_A8R8G8B8;
  393.         m_strFmtDesc.LoadString(IDS_FMTDESC_A8R8G8B8);
  394.         break;
  395.     case 1:
  396.         m_fmt = D3DFMT_A1R5G5B5;
  397.         m_strFmtDesc.LoadString(IDS_FMTDESC_A1R5G5B5);
  398.         break;
  399.     case 2:
  400.         m_fmt = D3DFMT_A4R4G4B4;
  401.         m_strFmtDesc.LoadString(IDS_FMTDESC_A4R4G4B4);
  402.         break;
  403.     case 3:
  404.         m_fmt = D3DFMT_R8G8B8;
  405.         m_strFmtDesc.LoadString(IDS_FMTDESC_R8G8B8);
  406.         break;
  407.     case 4:
  408.         m_fmt = D3DFMT_R5G6B5;
  409.         m_strFmtDesc.LoadString(IDS_FMTDESC_R5G6B5);
  410.         break;
  411.     case 5:
  412.         m_fmt = D3DFMT_X8R8G8B8;
  413.         m_strFmtDesc.LoadString(IDS_FMTDESC_X8R8G8B8);
  414.         break;
  415.     case 6:
  416.         m_fmt = D3DFMT_X1R5G5B5;
  417.         m_strFmtDesc.LoadString(IDS_FMTDESC_X1R5G5B5);
  418.         break;
  419.     case 7:
  420.         m_fmt = D3DFMT_R3G3B2;
  421.         m_strFmtDesc.LoadString(IDS_FMTDESC_R3G3B2);
  422.         break;
  423.     case 8:
  424.         m_fmt = D3DFMT_A8R3G3B2;
  425.         m_strFmtDesc.LoadString(IDS_FMTDESC_A8R3G3B2);
  426.         break;
  427.     case 9:
  428.         m_fmt = D3DFMT_X4R4G4B4;
  429.         m_strFmtDesc.LoadString(IDS_FMTDESC_X4R4G4B4);
  430.         break;
  431.     case 10:
  432.         m_fmt = D3DFMT_DXT1;
  433.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT1);
  434.         break;
  435.     case 11:
  436.         m_fmt = D3DFMT_DXT2;
  437.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT2);
  438.         break;
  439.     case 12:
  440.         m_fmt = D3DFMT_DXT3;
  441.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT3);
  442.         break;
  443.     case 13:
  444.         m_fmt = D3DFMT_DXT4;
  445.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT4);
  446.         break;
  447.     case 14:
  448.         m_fmt = D3DFMT_DXT5;
  449.         m_strFmtDesc.LoadString(IDS_FMTDESC_DXT5);
  450.         break;
  451.     }
  452.     UpdateData(FALSE);
  453. }
  454.  
  455.